package teamBattle

type TeamStatus int

const (
	// 组队状态
	TeamingStatus TeamStatus = 0

	// 解散队伍
	DismissStatus TeamStatus = 1

	// 战斗状态
	BattleStatus TeamStatus = 2

	// 终止状态（接收到战斗数据）
	EndStatus TeamStatus = 3

	// 调整战斗节点状态
	ChangeBattleNodeStatus TeamStatus = 4
)

// 状态转换表
var teamStatusTable map[TeamStatus]map[TeamStatus]TeamStatus

func init() {
	teamStatusTable = map[TeamStatus]map[TeamStatus]TeamStatus{
		TeamingStatus: map[TeamStatus]TeamStatus{
			BattleStatus:           BattleStatus,           // Teaming --> Battle
			EndStatus:              EndStatus,              // Teaming --> End
			DismissStatus:          DismissStatus,          // Teaming --> Dismiss
			ChangeBattleNodeStatus: ChangeBattleNodeStatus, // Teaming --> ChangeBattleNode
		},
		DismissStatus: map[TeamStatus]TeamStatus{
			EndStatus: EndStatus, // Dismiss --> End
		},
		BattleStatus: map[TeamStatus]TeamStatus{
			EndStatus: EndStatus, // Battle --> End
		},
		EndStatus: map[TeamStatus]TeamStatus{
			EndStatus: EndStatus, // End --> End
		}, // 队伍结束状态不能转换成其他状态
		ChangeBattleNodeStatus: map[TeamStatus]TeamStatus{
			TeamingStatus: TeamingStatus, // ChangeBattleNode --> Teaming
		},
	}
}

// 设置战斗完成后，可以设置为组队状态
func SetCanTeamingWhenBattle() {
	battleStatusTable := teamStatusTable[BattleStatus]
	battleStatusTable[TeamingStatus] = TeamingStatus // Battle --> Teaming
}

// 检查状态转换是否合法
func CheckStatus(nowStatus, targetStatus TeamStatus) bool {
	_, exist := teamStatusTable[nowStatus]
	if exist == false {
		return false
	}

	_, exist = teamStatusTable[nowStatus][targetStatus]
	if exist == false {
		return false
	}

	return true
}
